<?php

namespace App\Http\Requests;

use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class StatusFilter extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            //
            // 'filter'=>'integer|between:-1,2',
            //'page'=>'integer'
            //            'text'=>'required'
        ];
    }
    public function messages()
    {
        return [
            'filter.integer' => '状态选择错误',
            'filter.between' => '状态选择错误',
            // 'page.integer'=>'页码只能为数字',
            //            'text.required'=>'反馈意见为必填',
        ];
    }

    protected function failedValidation(Validator $validator)
    {
        throw (new HttpResponseException(response()->json([
            'code' => 100,
            'messages' => $validator->errors()->all(),
        ], 422)));
    }
}
